/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.qa.unittest.TestResults;
/*    */ import com.zimbra.qa.unittest.TestResults.Result;
/*    */ import com.zimbra.qa.unittest.ZimbraSuite;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.ArrayList;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class RunUnitTests
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/*    */     try
/*    */     {
/* 42 */       Class.forName("org.junit.Test");
/*    */     } catch (ClassNotFoundException e) {
/* 44 */       throw ServiceException.FAILURE("JUnit is not installed.  Unable to run unit tests.", e);
/*    */     }
/*    */     
/* 47 */     ZimbraSoapContext lc = getZimbraSoapContext(context);
/* 48 */     Element response = lc.createElement(AdminConstants.RUN_UNIT_TESTS_RESPONSE);
/*    */     
/* 50 */     List<String> testNames = null;
/* 51 */     for (Iterator<Element> iter = request.elementIterator("test"); iter.hasNext();) {
/* 52 */       if (testNames == null)
/* 53 */         testNames = new ArrayList();
/* 54 */       Element e = (Element)iter.next();
/* 55 */       testNames.add(e.getText());
/*    */     }
/*    */     
/* 58 */     com.zimbra.qa.unittest.TestUtil.fromRunUnitTests = true;
/*    */     TestResults results;
/* 60 */     TestResults results; if (testNames == null) {
/* 61 */       results = ZimbraSuite.runTestSuite();
/*    */     } else {
/* 63 */       results = ZimbraSuite.runUserTests(testNames);
/*    */     }
/* 65 */     Element resultsElement = response.addNonUniqueElement("results");
/*    */     
/* 67 */     int numPassed = 0;
/* 68 */     for (TestResults.Result result : results.getResults(true)) {
/* 69 */       Element completedElement = resultsElement.addNonUniqueElement("completed");
/* 70 */       completedElement.addAttribute("name", result.methodName);
/* 71 */       double execSeconds = result.execMillis / 1000.0D;
/* 72 */       completedElement.addAttribute("execSeconds", String.format("%.2f", new Object[] { Double.valueOf(execSeconds) }));
/* 73 */       completedElement.addAttribute("class", result.className);
/* 74 */       numPassed++;
/*    */     }
/*    */     
/* 77 */     int numFailed = 0;
/* 78 */     for (TestResults.Result result : results.getResults(false)) {
/* 79 */       Element failureElement = resultsElement.addNonUniqueElement("failure");
/* 80 */       failureElement.addAttribute("name", result.methodName);
/* 81 */       double execSeconds = result.execMillis / 1000.0D;
/* 82 */       failureElement.addAttribute("execSeconds", String.format("%.2f", new Object[] { Double.valueOf(execSeconds) }));
/* 83 */       if (result.errorMessage != null) {
/* 84 */         failureElement.setText(result.errorMessage);
/*    */       }
/* 86 */       failureElement.addAttribute("class", result.className);
/* 87 */       numFailed++;
/*    */     }
/*    */     
/* 90 */     response.addAttribute("numExecuted", numPassed + numFailed);
/* 91 */     response.addAttribute("numFailed", numFailed);
/* 92 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 97 */     notes.add("Do not need any right, all admins are allowed.");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/RunUnitTests.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */